Vuetify is a popular UI framework for Vue apps.
In this article, we’ll look at how to work with the Vuetify framework.
Card Media with Text
We can add a card with images and text.
For example, we can write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-card class="mx-auto" max-width="400">
<v-img
class="white--text align-end"
height="200px"
src="https://cdn.vuetifyjs.com/images/cards/docks.jpg"
>
<v-card-title>Lorem ipsum</v-card-title>
</v-img>
<v-card-subtitle class="pb-0">Lorem ipsum</v-card-subtitle>
<v-card-text class="text--primary">
<div>Lorem ipsum</div>
<div>Lorem ipsum</div>
</v-card-text>
<v-card-actions>
<v-btn color="orange" text>Lorem ipsum</v-btn>
<v-btn color="orange" text>Lorem ipsum</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({}),
};
</script>
We have the v-card
component with the v-img
inside it.
This way, we display the image on top.
v-card-title
has the title text.
v-card-subtitle
has the subtitle text.
And we add the v-card-text
to add the body text.
The v-card-actions
to add the actions.
v-btn
has the buttons at the bottom.
Grids
We can add a grid to the card.
For example, we can write:
<template>
<v-container>
<v-row>
<v-col col="12">
<v-card class="mx-auto" max-width="500">
<v-system-bar color="indigo darken-2" dark>
<v-spacer></v-spacer>
<v-icon>mdi-window-minimize</v-icon>
<v-icon>mdi-window-maximize</v-icon>
<v-icon>mdi-close</v-icon>
</v-system-bar>
<v-toolbar color="indigo" dark>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>Discover</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
</v-toolbar>
<v-container fluid>
<v-row dense>
<v-col v-for="card in cards" :key="card.title" :cols="card.flex">
<v-card>
<v-img
:src="card.src"
class="white--text align-end"
gradient="to bottom, rgba(0,0,0,.1), rgba(0,0,0,.5)"
height="200px"
>
<v-card-title v-text="card.title"></v-card-title>
</v-img>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-heart</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-bookmark</v-icon>
</v-btn>
<v-btn icon>
<v-icon>mdi-share-variant</v-icon>
</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</v-container>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
export default {
name: "HelloWorld",
data: () => ({
cards: [
{
title: "house",
src: "https://cdn.vuetifyjs.com/images/cards/house.jpg",
flex: 12,
},
{
title: "road",
src: "https://cdn.vuetifyjs.com/images/cards/road.jpg",
flex: 6,
},
{
title: "plane",
src: "https://cdn.vuetifyjs.com/images/cards/plane.jpg",
flex: 6,
},
],
}),
};
</script>
We have the v-container
component which has the v-row
and v-col
components to create the layout.
The layout is created according to the cards
array.
We also set the class and gradient to style the boxes.
Also, we add the v-card-actions
component to display the buttons at the bottom.
Conclusion
We can add media to cards.
Also, we can add text and buttons to the position we want.